using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Linq;

using LDAP.Entity;

namespace LDAP.BLL
{
    public class BizSpecialschedule
    {
		public const string ENTITY_KEY = "specialschedule";
		
        public static int Add(Specialschedule entry)
        {
            return !string.IsNullOrEmpty(Common.GetMapper(ENTITY_KEY, entry).Insert("Insert_Specialschedule", entry).ToString())? 1:0;
        }

        public static int Update(Specialschedule entry)
        {
            return Common.GetMapper(ENTITY_KEY, entry).Update("Update_Specialschedule", entry);
        }

        public static List<Specialschedule> GetByKey(string userId, DateTime start, DateTime end)
        {
            return GetAll().Where(l => l.UserId.Equals(userId, StringComparison.InvariantCultureIgnoreCase) && l.Status == 0 && l.FromDate <= start.Date && l.EndDate >= start.Date).ToList();
        }

        public static List<Specialschedule> GetAll()
        {
            string cacheKey = "alluser_specialschedule";
            if (Tools.CacheUtil.Exists(cacheKey))
                return Tools.CacheUtil.Get(cacheKey) as List<Specialschedule>;

            var all = Common.GetMapper(ENTITY_KEY, null).QueryForList<Specialschedule>("Select_Specialschedule", null).ToList();
            Tools.CacheUtil.Insert(cacheKey, all, 3600);
            return all;
        }

        public static int Delete(int id)
        {
           return Common.GetMapper(ENTITY_KEY, id).Delete("Delete_Specialschedule",id);
        }
    }
}

	